import com.maomao.MainApp;
import com.maomao.es.vector.DataImportService;
import com.maomao.es.vector.VectorDocument;
import com.maomao.es.vector.VectorDocumentRepository;
import com.maomao.es.vector.VectorizationService;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.core.List;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

/**
 * @author mao
 * @date 2025-05-30- 15:11
 * @descript
 */
//@RunWith(SpringRunner.class)
@Slf4j
@SpringBootTest(classes = MainApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class EstestVectorSearch {


    @Autowired
    private VectorDocumentRepository repository;

    @Autowired
    private VectorizationService vectorizationService;

    @Autowired
    private DataImportService dataImportService;


    @Test
    void testVectorSearch() {
        log.info("testVectorSearch测试.....");

        VectorDocument doc1 = new VectorDocument();
        doc1.setTitle("机器学习入门");
        doc1.setContent("机器学习是人工智能的重要分支");
        doc1.setTitleVector(vectorizationService.textToVector(doc1.getTitle()));
        doc1.setContentVector(vectorizationService.textToVector(doc1.getContent()));
        // 设置向量...

        VectorDocument doc2 = new VectorDocument();
        doc2.setTitle("深度学习基础");
        doc2.setContent("深度学习使用神经网络进行特征学习");
        doc2.setTitleVector(vectorizationService.textToVector(doc2.getTitle()));
        doc2.setContentVector(vectorizationService.textToVector(doc2.getContent()));


        // 设置向量...

        // repository.saveAll(List.of(doc1, doc2));

        dataImportService.query( vectorizationService.textToVector("我是毛建云"));

//        Page<VectorDocument> results = repository.findSimilarByContentVector(
//                vectorizationService.textToVector("AI技术"),
//                PageRequest.of(0, 10)
//        );
//
//        assertThat(results.getContent()).hasSize(2);
//        assertThat(results.getContent().get(0).getTitle()).contains("机器学习");
    }

}
